package com.jhx.service.impl;

import com.github.pagehelper.PageHelper;
import com.jhx.dao.UserMapper;
import com.jhx.pojo.SysUser;
import com.jhx.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SysUserServiceImpl implements ISysUserService {

   @Autowired
    private UserMapper userMapper;
    /**
     * 根据用户名密码查询用户
     * @param sysUser
     * @return
     */
    @Override
    public SysUser findUserByName(SysUser sysUser) {
        SysUser user = userMapper.findUserByName(sysUser);
        System.out.println(user);
        if(user!=null){
            return user;
        }
        return null;
    }
    /**
     * 查询用户(默认所有)
     * @param username
     * @return
     */
    @Override
    public List<SysUser> getAllUsers(String username,Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        return userMapper.getAllUsers(username);
    }
    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Override
    public SysUser getUserById(Integer id) {
        SysUser userById = userMapper.getUserById(id);
        return userById;
    }

    /**
     * 根据用户名查询用户
     */
    @Override
    public SysUser getUserByName(String username) {
        SysUser userByName = userMapper.getUserByName(username);
        return userByName;
    }

    /**
     * 添加用户
     */
    @Override
    public int addUser(SysUser sysUser) {
        int addUser = userMapper.addUser(sysUser);
        return addUser;
    }
    /**
     * 修改用户
     */
    @Override
    public int updateUser(SysUser sysUser) {
        int updateUser = userMapper.updateUser(sysUser);
        return updateUser;
    }
    /**
     * 删除用户
     */
    @Override
    public int deleteUser(Integer id) {
        int deleteUser = userMapper.deleteUser(id);
        return deleteUser;
    }
    /**
     * 批量删除
     */
    @Override
    public int allDeleteUsers(List<String> ids) {
        int allDeleteUsers = userMapper.allDeleteUsers(ids);
        return allDeleteUsers;
    }
}
